#-*- coding:utf-8 -*-

from django.db import models
from django.contrib.auth.models import User


class GType(models.Model):
    name = models.CharField(max_length=128)
    desc = models.TextField()
    ts = models.DateTimeField(auto_now=True)

    def __unicode__(self):
        return self.name


class Goods(models.Model):
    STATUS_NORMAL = 1
    STATUS_DELETE = 2
    STATUS_CHOICES = (
        (STATUS_NORMAL, "正常"),
        (STATUS_DELETE, "删除"),
    )

    PCT_CHOICES = ( (1, "六成新以下"), (2, "六成新"), (3, "七成新"), (4, "八成新"), (5, "九成新"), (6, "全新"),)

    user = models.ForeignKey(User)
    gtype = models.ForeignKey(GType)
    title = models.CharField(max_length=128)
    desc = models.TextField()
    price = models.PositiveIntegerField()
    pct = models.PositiveIntegerField(choices=PCT_CHOICES)
    phone = models.PositiveIntegerField()
    ts = models.DateTimeField(auto_now=True)

    status = models.PositiveIntegerField(choices=STATUS_CHOICES, default=STATUS_NORMAL)
    reads = models.PositiveIntegerField(default=0)
    comments = models.PositiveIntegerField(default=0)

    def __unicode__(self):
        return self.title


class Comment(models.Model):
    STATUS_NORMAL = 0
    STATUS_DELETED = 1
    STATUS_CHOICES = (
        (STATUS_NORMAL, "正常"),
        (STATUS_DELETED, "删除"),
    )

    customer = models.ForeignKey(User, related_name="trader")
    goods = models.ForeignKey(Goods)
    content = models.TextField()
    posttime = models.DateTimeField(auto_now=True)
    status = models.SmallIntegerField(choices=STATUS_CHOICES, default=STATUS_NORMAL)

    def __unicode__(self):
        return self.content
    

class GoodsImg(models.Model):
    owner = models.ForeignKey(User)
    goods = models.ForeignKey(Goods, null=True, blank=True)
    image = models.ImageField(upload_to="goods")
    relative_path = models.CharField(max_length=128)
    size = models.PositiveIntegerField(default=0)
    posttime = models.DateTimeField(auto_now=True)

    def __unicode__(self):
        return self.relative_path


